#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>

using namespace std;

//struct SQList
//{
//	int val;
//	SQList* next;
//};
//
//
//struct List
//{
//	int val;
//	int size;
//	int capacity;
//};



class  Solution
{
public:
	int sum = 0;
	int getSum(int n) 
	{
		while (n) {
			int t = n % 10;
			sum += t * t;
			n /= 10;
		}
		return sum;
	}
	bool isHappy(int n) 
	{
		int slow = n, fast = getSum(n);
		while (slow != fast)
		{
			slow = getSum(slow);
			fast = getSum(getSum(fast));
		}
		return slow == 1;
	}
};

int main()
{
	Solution s;
	cout << s.isHappy(2) << endl;
	return 0;
}